﻿
function ToggelNode(NodeId, PanelId, CollapseCss, ExpandCss) {

    $("#" + PanelId).toggle('fast');

    if ($("#" + NodeId).hasClass("" + CollapseCss + "")) {
        $("#" + NodeId).removeClass("" + CollapseCss + "");
        $("#" + NodeId).addClass("" + ExpandCss + "");
    }
    else {
        $("#" + NodeId).removeClass("" + ExpandCss + "");
        $("#" + NodeId).addClass("" + CollapseCss + "");
    }

}

function ToggleNodes() {
    $('div[isNode=true]').slideToggle('fast');
}

function OnTreeRbClick(DIV_ID, RB_ID, SelectedNodeID,isRbMode) {

    if (isRbMode) {
        $("div#" + DIV_ID + " :input").each(function() {
            this.checked = false;
        });
        
        var v = $("#" + RB_ID)[0];
        $(v).attr("checked", "true");
    }
    
    
    var SelectedNodeList = "";
    $("div#" + DIV_ID + " :input[checked=true]").each(function() {
        SelectedNodeList = SelectedNodeList + this.id + ",";
    }
    );

    $("#" + SelectedNodeID)[0].value = "";
    $("#" + SelectedNodeID)[0].value = SelectedNodeList;

}


function OnTreePostbackClick(hfEventID, SelectedNodeValue) {
    var thForm = document.forms[0];
    if (!thForm.onsubmit || (thForm.onsubmit() != false)) 
    {
        $("#" + hfEventID)[0].value = SelectedNodeValue;
        thForm.submit();
    }    
    
}


function CallAddNodeEvent(hfEventID, SelectedNodeValue) {
    var thForm = document.forms[0];
    if (!thForm.onsubmit || (thForm.onsubmit() != false)) {
        $("#" + hfEventID)[0].value = SelectedNodeValue;
        thForm.submit();
    }    
}

function CallRemoveNodeEvent(hfEventID, SelectedNodeValue) {
    var thForm = document.forms[0];
    if (!thForm.onsubmit || (thForm.onsubmit() != false)) {
        $("#" + hfEventID)[0].value = SelectedNodeValue;
        thForm.submit();
    }    
}

function OnMenuMethodSucceeded(result, eventArgs) {
    
    $(".MyContextMenu")[0].innerHTML = result.HTML;
    $(".MyContextMenu").css({ 'left': result.X, 'top': result.Y }).show();
    $(document).one('click', HideMenu);

}

function OnMenuMethodFailed(error) {
    alert(error.get_message());
}

function HideMenu() {
    $(".MyContextMenu").hide();
};



function TreeItemOnMouseOver(BtnAddID, BtnRemoveID) {
    $('#' + BtnAddID).show();
    if (BtnRemoveID.length > 0)
        $('#' + BtnRemoveID).show();
};


function TreeItemOnMouseOut(BtnAddID, BtnRemoveID) {
    $('#' + BtnAddID).hide();
    if (BtnRemoveID.length > 0)
        $('#' + BtnRemoveID).hide();
};

function TreeItemSubmit(hfNode,NodeId, hfEvent, EventID) {
    var thForm = document.forms[0];
    if (!thForm.onsubmit || (thForm.onsubmit() != false)) {
        $("#" + hfEvent)[0].value = EventID;
        $("#" + hfNode)[0].value = NodeId;
        thForm.submit();
    }    
    
};   